package com.liusy.taskengine.listeners;

import com.liusy.taskengine.ReleaseTask;


/**
 * 监听缓存任务多少时通知,可能会被多次执行
 * 
 * @author liusy 2012-12-12
 *
 */
public abstract class AbstractCacheTaskCountListener implements IReleaseTaskListener {
	
	
	//设置监听缓存任务多少时通知
	private int CacheTaskCount = 0;
	
	//执行次数0:N次
	private int ExecuteCount = 0;
	
	//已经执行的次数
	private int countFlag = 0;
	
	public AbstractCacheTaskCountListener(int cacheTaskCount){
		this.CacheTaskCount = cacheTaskCount;
	}
	public AbstractCacheTaskCountListener(int cacheTaskCount,int ExecuteCount){
		this.CacheTaskCount = cacheTaskCount;
		this.ExecuteCount = ExecuteCount;
	}
	@Override
	public void CacheTaskCountListener(ReleaseTask releaseTask) {
		countFlag++;
		CacheTaskCountExecute(releaseTask);
	}
	public abstract void CacheTaskCountExecute(ReleaseTask releaseTask);
	
	@Override
	public void CacheTaskFinishListener(ReleaseTask releaseTask) {
		// TODO Auto-generated method stub
		
	}
	public int getCacheTaskCount()
	{
		return this.CacheTaskCount;
	}
	public boolean isPermissionExecute()
	{
		if(ExecuteCount==0 || countFlag<=ExecuteCount)
			return true;
		return false;
	}
	
	public int getExecuteCount()
	{
		return this.ExecuteCount;
	}

	public int getCountFlag()
	{
		return this.countFlag;
	}
	
	
	@Override
	public void TaskReleaseFinishListener(ReleaseTask releaseTask) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void StartCacheTaskListener(ReleaseTask releaseTask) {
		// TODO Auto-generated method stub
		
	}
	

	
}
